package com.dongrj.framework.web.runner;

import com.dongrj.framework.web.utils.SpringUtils;
import org.springframework.beans.BeansException;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.util.Map;

/**
 * @author dongrongjun
 * @date 2020/4/2
 *//**
 * @author dongrongjun
 * @date 2020/4/2
 */
public class SpringBootAfterRunner implements ApplicationContextAware, ApplicationRunner {

    private ApplicationContext applicationContext;

    @Override
    public void run(ApplicationArguments args) {
        SpringUtils.configApplicationContext(applicationContext);
        Map<String, SpringBootAfterStartUp> beansOfTypes = applicationContext.getBeansOfType(SpringBootAfterStartUp.class);
        beansOfTypes.values().forEach(SpringBootAfterStartUp::run);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
